<?php
namespace app\admin\controller;
use app\service\roominfoService;
use app\service\strangerApplyService;
use think\facade\View;
use think\facade\Log;

ini_set('max_execution_time','0');
class Stranger extends Common{
    public function index(){
        //查询小区信息
        $com = $this->pidTokenId();

        //$whe['community_id'] = array('in',$com['community_id']);//所有小区ID
        $whe[] = ['community_id','in',$com['community_id']];//所有小区ID
        $communitylist = (new roominfoService())->communityList($whe);

        $community_id = $com['com_id'];
        View::assign('communitylist',$communitylist);


        //查询
        $data = request()->get();


        if (!empty($data)){
            if(!empty($data['community_id'])){
                $where['community_id'] = $data['community_id'];//小区名称
            }else{
                $where['community_id'] = "";
            }


            if(!empty($data['status'])){
                $where['status'] = $data['status'];//状态
            }else{
                $where['status'] = "";
            }
            View::assign('where',$where);   
            $where = array_filter($where);
        }else{
            $where = null;
        }
        $export = $where;
        $export = json_encode($export);
        $export = str_replace("\"","|",$export);
        View::assign('export',$export);
        $page = request()->has('page') ? request()->get('page') : 1;
        //查询房屋条数
       
        $number =(new strangerApplyService())->userCount($community_id,$where);
        //var_dump($number);
        View::assign('number',$number);
        //查询房屋信息
        
        $roomlist = (new strangerApplyService())->userList($community_id,$page,$where);
        //var_dump($roomlist);
        
        //判断是否有数据
        if(!empty($number)){
            foreach($roomlist as $room){
                

                $list[] = $room;
                View::assign('list',$list);
            }
        }else{
            View::assign('list',$roomlist);
        }
        //View::assign('list',$roomlist);
        View::assign('roomlist',$roomlist);
       
        foreach ($data as $k => $v) {
            View::assign($k, $v);
        }


        return View::fetch('index');
    }

   

}